<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="UTF-8">
<title>签名配置</title>

<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-table.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/style.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-editable.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/dropzone.css">

</head>

<body>
	<div th:insert="~{header :: copy}"></div>

	<div class="panel panel-default" style="padding-top: 80px;margin-left: 50px;margin-right: 50px;border: 0px">
		<div class="panel-heading" style="background: white;">
			<font size="5px">签名配置</font>
		</div>
		<div class="panel-body">
			<div id="toolbar" class="btn-group">
				<button id="btn_add" type="button" class="btn btn-default"
					data-toggle="modal" data-target="#addModel">
					<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				</button>
			</div>
			<table id="table"></table>
		</div>
	</div>

	<div id="addModel" class="modal fade" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content" style="width: 500px; align-self: center;">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true"></button>
					<h4 class="modal-title">
						<i class="icon-pencil"></i> <span id="lblAddTitle"
							style="font-weight: bold">添加签名配置</span>
					</h4>
				</div>
				<div class="modal-body" style="text-align: center;">
					<form id='searchForm' action="apiDefine/saveOrUpdate"
						class="bs-example bs-example-form" role="form"
						style="align-self: center;">
						<div class="input-group">
							<span class="input-group-addon" style="width: 100px"><i
								class="icon-th">商户编号</i></span> <input type="text" class="form-control"
								name="partnerCode" id="signInfo-partnerCode" placeholder="abc"
								onblur="validateEmptyContent('signInfo-partnerCode','partnerCodeMsgSpan')"
								onkeyup="validateEmptyContent('signInfo-partnerCode','partnerCodeMsgSpan')">
							<span class="input-group-addon" id="partnerCodeMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">签名ID</i></span> <input type="text"
								class=" form-control" name="signId" id="signInfo-signId"
								onblur="validateLegalNumber('signInfo-signId','signIdMsgSpan')"
								onkeyup="validateLegalNumber('signInfo-signId','signIdMsgSpan')">
							<span class="input-group-addon" id="signIdMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">私钥路径</i></span> <input type="text"
								class=" form-control" name="privateKeyPath"
								id="signInfo-privateKeyPath"
								onblur="validateEmptyContent('signInfo-privateKeyPath','privateKeyPathMsgSpan')"
								onkeyup="validateEmptyContent('signInfo-privateKeyPath','privateKeyPathMsgSpan')">
							<span class="input-group-addon" id="privateKeyPathMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">公钥路径</i></span> <input type="text"
								class=" form-control" name="publicKeyPath"
								id="signInfo-publicKeyPath"
								onblur="validateEmptyContent('signInfo-publicKeyPath','publicKeyPathMsgSpan')"
								onkeyup="validateEmptyContent('signInfo-publicKeyPath','publicKeyPathMsgSpan')">
							<span class="input-group-addon" id="publicKeyPathMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">签名方式</i></span>
							<select id="signInfo-signType" style="height: 28px"></select>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">是否激活</i></span>
							<select style="height: 28px" name = "isActivated" id="signInfo-isActivated">
								<option value="1">是</option>
								<option value="0" selected="selected">否</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="ID" name="ID" />
					<button type="submit" class="btn btn-primary"
						onclick="saveSignInfo()" data-dismiss="modal">确定</button>
					<button type="button" class="btn green" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>

</body>
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/jquery-ui.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/js/bootstrap-table.js"></script>
<script src="bootstrap/js/bootstrap-editable.min.js"></script>
<script src="bootstrap/js/dropzone.js"></script>
<script src="bootstrap/js/bootstrap-table-editable.js"></script>
<script src="bootstrap/js/gateway.js"></script>
<script type="text/javascript">
	function saveSignInfo() {
		var partnerCode = $("#signInfo-partnerCode").val();
		var signId = $("#signInfo-signId").val();
		var privateKeyPath = $("#signInfo-privateKeyPath").val();
		var publicKeyPath = $("#signInfo-publicKeyPath").val();
		var signType = $("#signInfo-signType").val();
		var isActivated = $("#signInfo-isActivated").val();

		var data = {
			partnerCode : partnerCode,
			signId : signId,
			privateKeyPath : privateKeyPath,
			publicKeyPath : publicKeyPath,
			signType : signType,
			isActivated : isActivated
		}

		saveOrUpdateGateWayConfigurations(data, "/signInfo/saveOrUpdate", "add");

	}
</script>
<script type="text/javascript">
	$(function() {
		$("#addModel").draggable();//为模态对话框添加拖拽

		var signTypeArray = new Array();
		
		//加载加密类型
		$.ajax({
			type:"get",
			url:"/constants/getEncryptTypes",
			async : false,
			success : function(data) {
				var types = "";
				for(var i = 0; i < data.length; i++ ) {
					signTypeArray[i] = {value:data[i], text:data[i]};
					types += "<option value='"+ i +"'>" + data[i] +"</option>";
				}
				$("#signInfo-signType").append(types);
			},
			error : function() {
				alert("加密类型加载失败!");
			}
		});
		
		var curRow = {};
		$('#table').bootstrapTable(
				{
					url : '/signInfo/listAll',
					pagination : true,
					pageSize : 10,
					pageNumber : 1,
					search : true,
					searchAlign : "right",
					toolbar : "#toolbar",
					columns : [ {
						field : 'id',
						title : 'id'
					}, {
						field : 'partnerCode',
						title : '商户编号',
						editable : {
							type : 'text',
							title : '商户编号',
							validate : function(v) {
								if (!v)
									return '商户编号不能为空';

							}
						}
					}, {
						field : 'signId',
						title : '签名ID',
						editable : {
							type : 'text',
							title : '签名ID',
							validate : function(v) {
								if (!isPositiveInteger(v))
									return '签名ID只能为正整数';

							}
						}
					}, {
						field : 'privateKeyPath',
						title : '私钥路径',
						editable : {
							type : 'text',
							title : '私钥路径',
							validate : function(v) {
								if (!v)
									return '私钥路径不能为空';

							}
						}
					}, {
						field : 'publicKeyPath',
						title : '公钥路径',
						editable : {
							type : 'text',
							title : '公钥路径',
							validate : function(v) {
								if (!v)
									return '公钥路径不能为空';

							}
						}
					}, {
						field : 'signType',
						title : '签名类型',
						editable : {
		                    type: 'select',
		                    title: '加密类型',
		                    source: signTypeArray
						}
					}, {
						field : 'formatCreateTime',
						title : '创建时间'
					} , {
						field : 'formatUpdateTime',
						title : '修改时间'
					}  ],
					onClickRow : function(row, $element) {
						curRow = row;
					},
					onEditableSave : function(field, row, oldValue, $el) {
						var data = {
								id : row.id,
								partnerCode : row.partnerCode,
								signId : row.signId,
								privateKeyPath : row.privateKeyPath,
								publicKeyPath : row.publicKeyPath,
								signType : row.signType,
								isActivated : row.isActivated
							}
						
						saveOrUpdateGateWayConfigurations(data,
								"/signInfo/saveOrUpdate", "update");
					}
				});
	});
</script>

</html>